package com.ruoyi.yl.consultMange.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yl.consultMange.vo.YlConsultationVo;
import com.ruoyi.yl.consultMange.service.IYlConsultationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 咨询Controller
 *
 * @author Ming
 * @date 2025-10-21
 */
@Api(tags = "咨询Controller")
@RestController
@RequestMapping("/pg/consultation")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class YlConsultationController extends BaseController {

    private final IYlConsultationService ylConsultationService;

    @ApiOperation("查询咨询列表")
    @GetMapping("/list")
    public TableDataInfo<YlConsultationVo> list(YlConsultationVo entity) {
        return ylConsultationService.queryList(entity);
    }

    @ApiOperation("查询咨询所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(YlConsultationVo entity) {
        return AjaxResult.success("查询成功", ylConsultationService.queryAll(entity));
    }

    @ApiOperation("导出咨询列表")
    @Log(title = "咨询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlConsultationVo entity) {
        List<YlConsultationVo> list = ylConsultationService.queryAll(entity);
        ExcelUtil<YlConsultationVo> util = new ExcelUtil<>(YlConsultationVo.class);
        util.exportExcel(response, list, "咨询数据");
    }

    @ApiOperation("获取咨询详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", ylConsultationService.queryById(id));
    }

    @ApiOperation("新增咨询")
    @Log(title = "咨询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlConsultationVo entity) {
        return toAjax(ylConsultationService.save(entity));
    }

    @ApiOperation("修改咨询")
    @Log(title = "咨询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlConsultationVo entity) {
        return toAjax(ylConsultationService.updateById(entity));
    }

    @ApiOperation("删除咨询")
    @Log(title = "咨询", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ylConsultationService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
